home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
MOTOROLA
/
6805V107
/
TEST.SRC
< prev
next >
Wrap
Text File
|
1995-05-03
|
12KB
|
424 lines
title 'Keyless Lock - AN863'
* Motorola Evaluation Program: MC1468705F2 Keyless Lock
* See Motorola application note AN-863
*
* This was typed in from a Motorola application-note, as
* a simple demonstration of the software package.
* It does not exhibit every capability of the Assembler
* (eg complex operand expressions), but it will serve
* as a start.
*
* If you want to emulate this code, be sure to select
* "68705P3" emulation mode.
*
include '68705f2.asm' Standard definitions
ORG $40
*
CTRL FCB 0
CODE RMB 8 ENTRY CODE LOCATION
NCODE RMB 8 ENTERED CODE LOCATION
VERI RMB 8 VERIFY CODE LOCATION
TEMPX FCB 0 TEMPORARY REG FOR X
TEMP FCB 0 ANOTHER TEMP REG
TEMP2 FCB 0 TIME COUNTER (UPPER)
TEMP1 FCB 0 TIME COUNTER (LOWER)
TEMPA1 FCB 0 TIME DELAY REGISTER
TEMPA FCB 0
VALID1 FCB 0
VALID2 FCB 0
TEMP3 FCB 0
*
*
BLANK EQU $00 BLANK CHARACTER TO LCD
DASH EQU $20 DASH
*
****************************************************
*
* Equates, etc., to resolve references to code
*
****************************************************
*
ORG $B9
VERIFY MSG 'VERIFY'
*
ORG $C1
ERROR MSG 'ERROR'
*
ORG $C9
OPEN1 MSG 'OPEN'
*
ORG $D1
CHG MSG 'CHANGE'
*
*
****************************************************
* *
* NB Changed code here!! *
* The original definitions follow: these pointed *
* to a firmware debugger (not part of this code) *
* To make this code run (in emulation), they are *
* replaced by EQU's to the code start. *
* *
*RESET EQU $F8 Restart firmeware debugger *
*MONIT EQU $179 SWI instruction: trap *
* *
****************************************************
*
eject
****************************************************
*
ORG $343
*
* INITIALISATION GOES HERE
*
RESET EQU $
MONIT EQU $
LOCK LDA #$F0
STA PORTA+DDR
CLR PORTB CLEAR PORTB
CLR CTRL
CLRA
COMA GET FF
STA PORTB+DDR SET PORTB DDR TO OUT
BEGIN JSR CLEAR
*
*
STOP STOP PROCESSOR AND W
BGIN1 JSR CLEAR CLEAR DISPLAY
CLI
*
* GET NUMBER
*
LDX #NCODE GET RAM STORAGE SPOT
BSR GET8 GET 8 NUMBERS
*
* NOW THAT WE HAVE THE EIGHT-DIGIT NUMBER COMP
* THE VALID ENTRY CODE AND THE CHANGE CODE. IF
* NO MATCH INCREMENT ALARM COUNTER.
*
LDX #$08 GET COUNT
MOR2 LDA NCODE-1,X GET FIRST/N NUMBER
CMP CHG-1,X IS IT THE CHANGE COD
BNE MORR IF Z=0 NOT EQUAL
DECX DECREMENT COUNTER
BNE MOR2 DO MORE IF NO
BRA VERI1
*
*
MORR LDX #CODE GET FIRST LOCATION
JSR BLCMP COMPARE THEM
INCA CHECK FOR EQUAL
BNE OPEN IF NOT 0 THEN EQUAL
BRA ALARM1
*
*
* CHANGE ENTRY CODE SECTION WITH VERIFY
*
VERI1 JSR CLEAR CLEAR DISPLAY
VERI2 LDX #NCODE GET RAM LOCATION
BSR GET8 GET NUMBER
*
* SEND THE WORD VERIFY HERE
*
LDX #$08 GET COUNTER
LOOP LDA VERIFY-1,X
JSR DSPLY
DECX
BNE LOOP
*
*
LDX #VERI GET RAM LOCATION
BSR GET8 GET NUMBER
*
* COMPARE VERIFY
*
LDX #NCODE GET FIRST NUMBER
JSR BLCMP COMPARE
INCA CHECK FOR FF
BEQ CNT2 IF ZERO THEN ERROR
*
* VERIFY OK
*
LDX #$08
MOR6 LDA VERI-1,X GET START OF CODE
STA CODE-1,X STORE IT
DECX
BNE MOR6 IF NOT DONE DO MOR6
JMP BEGIN GOTO START OF PROGRA
*
* IF IT GETS HERE THERE HAS BEEN A VERIFY ERRO
* SEND THE WORD ERROR TO THE LCD
*
CNT2 LDX #$08 GET COUNTER
LOOP2 LDA ERROR-1,X
JSR DSPLY
DECX
BNE LOOP2
BRA VERI2
*
* THIS IS THE OPEN LOCK PART
*
OPEN LDX #$08 GET COUNTER
LOO3 LDA OPEN1-1,X
JSR DSPLY
DECX
BNE LOO3
*
BRCLR 7,CTRL,NXT ALARM BIT SET?
BCLR 7,CTRL RESET IT IF YES
BCLR 2,PORTB CLEAR ALARM BIT TO O
NXT LDA #$F8
STA PORTB
*
*
* LOOP FOR APPROX. 8 SECONDS
*
LDX #$FF GET COUNT
JSR TMDLY DELAY
*
* CLOSE LOCK
*
CLRA
STA PORTB
JMP BEGIN
*
* THIS IS THE ALARM SPOT
*
ALARM1 INC CTRL INCREMENT ALARM COUN
BRCLR 1,CTRL,NXT2 CHECK FOR ALARM =2
BSET 2,PORTB IF ALARM=2, THEN SET
NXT2 JMP BEGIN GOTO START
*
*
* THIS IS THE SUBROUTINE GET8
*
GET8 LDA #$08 GET NUMBER COUNT
STA TEMP1 SAVE COUNTER
SCAN2 LDA #$40 GET UPPER COUNTER
STA TEMP2 SAVE COUNTER
SCAN1 LDA #$FF GET LOWER COUNTER
STA TEMP SAVE COUNTER
*
*
****************************************************
* THIS SUBROUTINE SCANS A 4 x 3 MATRIX OF KEYS
* VALUE OF 1-12 IN THE A ACCUMULATOR IF IT FINDS ONE
* OTHERWISE IT RETURNS A VALUE OF $FF IF NO KEY IS D
* ONLY REGISTER DESTROYED IS THE A ACCUMULATOR ALL O
* ARE LEFT ALONE.
****************************************************
*
SCAN EQU $
LDA #$40
STA PORTA SELECT ONE COLUMN AT
STX TEMPX SAVE X REGISTER
LDX #$03 COUNT THE COLUMN
*
LOOPA LDA PORTA CHECK IF KEY PRESSED
AND #$0F CLEAR UPPER NIBBLE
BNE DEBNCE BRANCH IF KEY PRESSE
NOKEY LSR PORTA NEXT COLUMN
DECX DECREMENT COLUMN COU
BNE LOOPA NO KEY PRESSED
DECX RETURN X WITH $FF
*
EXIT TXA
LDX TEMPX
BRA CK
*
*
FOUND LSRA SHIFT IF THE ROW INF
BCS CHECK
INCX ADD 3 FOR EVERY ROW
INCX
INCX
BRA FOUND
*
CHECK CPX #$0A
BLO EXIT NUMBER RETURNED <10
CPX #$0B
BEQ FIX INPUT NUMBER IS ZERO
INVAL LDX #$FF INVALID ENTRY RETURN
BRA EXIT
FIX LDX #$00 RETURN 0 IN X
BRA EXIT
*
DEBNCE STA TEMPA SAVE A REGISTER
CLR VALID1
CLR VALID2
DBNCE1 LSRA
BCS ONEKEY CHECK TO MAKE SURE O
INC VALID1
BRA DBNCE1 CONTINUE CHECK
ONEKEY CMP #$00 ONLY ONE KEY PRESSED
BNE INVAL NO, MORE THAN ONE KE
*
STX TEMP3
LDX #$FF
MOR10 DECX
BNE MOR10
LDX TEMP3
*
LDA PORTA CHECK TO MAKE SURE O
AND #$0F
ROWCK1 LSRA
BCS ONEKY1
INC VALID2
BRA ROWCK1
ONEKY1 LDA VALID2
CMP VALID1 SAME KEY PRESSED
BNE INVAL NO! SAME KEY NOT PRE
*
*
UPKEY LDA PORTA CHECK TO MAKE SURE K
AND #$0F
BNE UPKEY RELEASED? NO
LDA TEMPA VALID KEY PRESS
BRA FOUND CALCULATE KEY NUMBER
*
*
CK INCA INCREMENT A Z=1=NOKE
BNE BACK GO BACK IF NOT ZERO
STX TEMPX SAVE X
LDX #$01
BSR TMDLY DELAY FOR 32MS
LDX TEMPX GET X
DEC TEMP DEC LOWER COUNTER
BNE SCAN CHECK FOR MORE KEYS
DEC TEMP2 DEC UPPER COUNTER
BNE SCAN1 CHECK FOR MORE KEYS
*
* CLEAR DISPLAY HERE
*
BCK JSR CLEAR
RSP
JMP BEGIN
BACK DECA ADJUST KEY NUMBER
STA ,X SAVE NUMBER
LDA #DASH
BSR DSPLY
INCX INC POINTER
DEC TEMP1 DEC COUNTER
BNE SC1 IF NOT 8 GET MORE
RTS RETURN
SC1 JMP SCAN2
*
* THIS IS THE DISPLAY SUBROUTINE
*
DSPLY STX TEMPX SAVE X
LDX #$08 GET COUNTER
CLC CLEAR CARRY
MOR8 LSLA ROTATE TO GET BIT
BLO ONE ONE OR A ZERO
BCLR 0,PORTB SEND ZERO
BRA STRB
ONE BSET 0,PORTB SEND ONE
STRB BSET 1,PORTB SEND STROBE
BCLR 1,PORTB TO ENTER DATA
DECX DEC COUNTER
BNE MOR8
LDX TEMPX
RTS RETURN
*
CLEAR CLRA
LDX #$08
LOO BSR DSPLY
DECX
BNE LOO
RTS
*
* THIS IS THE BLOCK COMPARE ROUTINE
*
* X-CONTAINS THE LOWER ORDER LOCATION
* THIS ROUTINE ASSUMES THE ONE TO EIGHT
* DIGIT NUMBERS ARE NEXT TO EACH OTHER
*
BLCMP LDA #$08 GET COUNTER
STA TEMPA1 SAVE COUNTER
MOR1 LDA ,X GET IT
CMP #$08,X COMPARE
BNE RT IF NO COMPARE GO BAC
INCX
DEC TEMPA1 DEC COUNTER
BNE MOR1 IF NOT DONE DO MORE
CLRA GET ALL ZEROS
BRA RT1
RT CLRA
COMA GET ALL ONES
RT1 RTS RETURN 00=EQUAL FF=N
*
*
* THIS IS THE TIME DELAY ROUTINE
*
* X CONTAINS THE NUMBER OF TIME-OUTS THAT THE
* COUNTER WILL GO THRU
* ONE TIMEOUT=32 MILLISEC.
*
TMDLY STA TEMPA1 SAVEACC.
MOR LDA #$47 GET TIMER CONTROL BY
STA TIMER+1 STORE
LDA #$FF GET ALL ONES
STA TIMER STORE
HERE BRCLR 7,TIMER+1,HERE POLL TIMER IRQ BIT F
DECX DEC COUNTER
BNE MOR IF NOT DONE DO MORE
RTS RETURN
*
*
* THIS IS THE IRQ DRIVER TO GET THE WHOLE THIN
*
INT RSP
CLI
JMP BGIN1
*
*
* SET UP EXTERNAL INTERRUPT VECTOR HERE
*
****************************************************
*
* VECTORS
*
****************************************************
*
ORG MEMSIZ-10
FDB BGIN1
FDB BGIN1
FDB INT
FDB MONIT SWI
FDB RESET